package cn.wolfcode.${project}.web.controller;

import cn.wolfcode.${project}.domain.${capitalize};
import cn.wolfcode.${project}.query.${capitalize}QueryObject;
import cn.wolfcode.${project}.service.DestinationService;
import cn.wolfcode.${project}.service.${capitalize}Service;
import cn.wolfcode.${project}.vo.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @author ${author}
 * @Date ${.now?string("yyyy-MM-dd HH:mm")}
 */
@Controller
@RequestMapping("/${uncapitalize}")
public class ${capitalize}Controller {
    @Autowired
    private ${capitalize}Service ${uncapitalize}Service;

    /**
     * ${chinese}高级查询
     * @param model
     * @param qo 查询条件
     * @return
     */
    @RequestMapping("/list")
    public Object query(Model model, @ModelAttribute("qo") ${capitalize}QueryObject qo) {
        Page<${capitalize}> page = ${uncapitalize}Service.query(qo);
        model.addAttribute("page",page);
        return "${uncapitalize}/list";
    }


    /**
     * 新增或更新区域
     * @param ${uncapitalize}
     * @return
     */
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(${capitalize} ${uncapitalize},HttpServletResponse response) {
        ${uncapitalize}Service.saveOrUpdate(${uncapitalize});
        response.setContentType("application/json;charset:utf-8");
        return JsonResult.success();
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(String id) {
        ${uncapitalize}Service.delete(id);
        return JsonResult.success();
    }
}
